<script setup lang="ts">
import {EXAMINE_STATUS} from "~/const/Maps";

definePageMeta({
  title:'代卖域名列表',
  layout:'admin',
  keepalive:true,
})
const form=reactive({
  limit:20,
  page:1,
  domain:'',//模糊搜索-域名
});
const {data:list,refresh}=await useServerGet('/backend/agent/getList',form)
const search=()=>{
  refresh&&refresh();
}
const audit= async (row,status)=>{
  ElMessageBox.confirm('确定审核吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then( async () => {
    const {data,code}=await usePost('/backend/agent/examine',{id:row.id,examine_status:status})
    if(code==200){
      refresh&&refresh();
    }
  }).catch(() => {
  });
}
</script>

<template>
  <div>
    <el-card>
      <div class="flex">
        <div class="w-52 mr-2">
          <el-input placeholder="请输入域名" v-model="form.domain" class="w-40" clearable></el-input>
        </div>
        <div class="w-20">
          <el-button type="primary" @click="search">搜索</el-button>
        </div>
      </div>
    </el-card>
    <el-card class="mt-4">
      <el-table :data="list.data.list" :header-cell-style="{'text-align':'center'}" :cell-style="{'text-align':'center'}" class="h-[620px] overflow-auto">
        <el-table-column prop="id" label="ID"></el-table-column>
        <el-table-column prop="domain" label="域名"></el-table-column>
        <el-table-column prop="price" label="价格"></el-table-column>
        <el-table-column prop="user_phone" label="手机号"></el-table-column>
        <el-table-column prop="register_time" label="注册时间"></el-table-column>
        <el-table-column prop="expiration_time" label="到期时间"></el-table-column>
        <el-table-column prop="state" label="状态">
          <template #default="{row}">
            {{EXAMINE_STATUS[row.examine_status]}}
          </template>
        </el-table-column>
        <el-table-column prop="updated_at" label="更新时间"></el-table-column>
        <el-table-column prop="created_at" label="创建时间"></el-table-column>
        <el-table-column label="操作" width="200px">
          <template #default="{row}">
            <div class="flex justify-center" v-if="!row.examine_status">
              <template v-for="(label,value) in EXAMINE_STATUS">
                <el-button :type="value*1==10?'primary':''" @click="audit(row,10)" v-if="value*1">{{ label }}</el-button>
              </template>
            </div>
            <div v-else>-</div>
          </template>
        </el-table-column>
      </el-table>
      <MyPage v-model:page="form.page" v-model:perpage="form.limit" v-model:total="list.data.count" @change="refresh"></MyPage>
    </el-card>
  </div>
</template>

<style scoped lang="scss">

</style>